package com.ruoyi.common.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@Component
@Configuration
@ConfigurationProperties(prefix="spring.redis")
public class JedisConfig {

    public static String host;

    public static int port;

    public static String password;

    public void setHost(String host) {
        JedisConfig.host = host;
    }

    public void setPort(int port) {
        JedisConfig.port = port;
    }

    public void setPassword(String password) {
        JedisConfig.password = password;
    }

    @Bean
    public JedisPool jedisPool() {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(200);
        jedisPoolConfig.setMaxIdle(70);
        jedisPoolConfig.setMinIdle(10);
        jedisPoolConfig.setMaxWaitMillis(-1);

        System.err.println(host);

        return new JedisPool(jedisPoolConfig, host, port, 3000, password);
    }
}
